package com.dtkeys.organization.services;

import com.dtkeys.organization.model.Organization;
import com.dtkeys.organization.repository.OrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * Created by Administrator on 2020/5/20.
 */

@Service
public class OrganizationService {
    @Autowired
    private OrganizationRepository orgRepository;

    public Organization getOrg(String organizationId) {
        //Organization organization = orgRepository.findById(organizationId);
        Organization organization = orgRepository.findOrganizationById(organizationId);
        System.out.println("organizationId == " + organizationId + "  organization == " + organization);
        return organization;
    }

    public void saveOrg(Organization org) {
        org.setId(UUID.randomUUID().toString());
        orgRepository.save(org);
    }

    public  void updateOrg(Organization org) {
        orgRepository.save(org);
    }

    public void deleteOrg(Organization org) {
        orgRepository.delete(org.getId());
    }
}
